/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Threads;

import com.mysql.jdbc.Statement;
import cparc.cadastroProp;
import cparc.conexao;
import java.awt.Frame;
import java.sql.ResultSet;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Administrador
 */
public class cadPropTab extends java.lang.Thread {

    cadastroProp cadProp = null;
    DefaultTableModel modelo = null;
    String sqlCons = null;
    float total = 0;
    int current = 0;
    
    public void retTab(DefaultTableModel m){
    
    cadProp.setTableModel(m);
    }


public void setValues(cadastroProp prop,DefaultTableModel m, String sql){

    cadProp = prop;
    modelo = m;
    sqlCons = sql;
}

    @Override
    public void run(){

        Statement stm = null;
        String result = null;
        //String consulta = "SELECT PCOD, PNOM FROM CPARC.CAD_PROP ORDER BY PNOM ASC";
        String totProp = "SELECT COUNT(PCOD) AS CONT FROM CPARC.CAD_PROP";
        
        int i=0;

        try  {
        stm = (Statement) conexao.getConnection(true).createStatement();
                
        ResultSet rs = stm.executeQuery(totProp);
        rs.next();
        total = rs.getInt("CONT");

        rs = stm.executeQuery(sqlCons);

        while(rs.next()){
        modelo.addRow(new String[] {Integer.toString(rs.getInt("PCOD")), rs.getString("PNOM")});
        modelo.fireTableCellUpdated(i, 0);
        modelo.fireTableCellUpdated(i, 1);
        i++;
        
        current = i;
        cadProp.setLabProg((current+" de " + (int)total));
        //System.out.println((int)percent);
        }

        }
        catch(Exception e){
            String status = e.getMessage();
            System.out.println(status);
        }
        cadProp.setLabProg((current+" de " + (int)total));

        retTab(modelo);

    }
}
